home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-pyorbit / examples / c-inproc / c-impl.c next >
Encoding:
C/C++ Source or Header  |  2008-05-01  |  3.0 KB  |  128 lines

  1. #define ORBIT2_STUBS_API
  2.  
  3. #include <Python.h>
  4. #include <pyorbit.h>
  5. #include "testcall.h"
  6.  
  7. typedef struct {
  8.     POA_PyORBit_TestCall baseServant;
  9.     PyORBit_TestCall this;
  10. } PyORBit_TestCall_Servant;
  11.  
  12.  
  13. static void
  14. TestCall_op1(PortableServer_Servant servant,
  15.          PyORBit_TestCall other,
  16.          CORBA_Environment *ev)
  17. {
  18.     PyORBit_TestCall_Servant *self = (PyORBit_TestCall_Servant *)servant;
  19.     printf("  C impl of TestCall.op1 invoked\n");
  20.     PyORBit_TestCall_op2(other, self->this, ev);
  21. }
  22.  
  23. static void
  24. TestCall_op2(PortableServer_Servant servant,
  25.          PyORBit_TestCall other,
  26.          CORBA_Environment *ev)
  27. {
  28.     printf("  C impl of TestCall.op2 invoked\n");
  29.     PyORBit_TestCall_op3(other, ev);
  30. }
  31.  
  32. static void
  33. TestCall_op3(PortableServer_Servant servant,
  34.          CORBA_Environment *ev)
  35. {
  36.     printf("  C impl of TestCall.op3 invoked\n");
  37. }
  38.  
  39. static PortableServer_ServantBase__epv TestCall_base_epv = {
  40.     NULL,
  41.     NULL,
  42.     NULL
  43. };
  44.  
  45. static POA_PyORBit_TestCall__epv TestCall_epv = {
  46.     NULL,
  47.     TestCall_op1,
  48.     TestCall_op2,
  49.     TestCall_op3
  50. };
  51.  
  52. static POA_PyORBit_TestCall__vepv TestCall_vepv = {
  53.     &TestCall_base_epv,
  54.     &TestCall_epv
  55. };
  56.  
  57.  
  58. static CORBA_Object
  59. create_TestCall(CORBA_ORB orb, CORBA_Environment *ev)
  60. {
  61.     /* hold the actual servant/objref ... */
  62.     static PyORBit_TestCall_Servant servant;
  63.  
  64.     PortableServer_ObjectId *objid;
  65.     PortableServer_POA poa;
  66.  
  67.     if (servant.this) {
  68.     return CORBA_Object_duplicate(servant.this, ev);
  69.     }
  70.     servant.baseServant._private = NULL;
  71.     servant.baseServant.vepv = &TestCall_vepv;
  72.  
  73.     POA_PyORBit_TestCall__init((PortableServer_ServantBase *)&servant, ev);
  74.     g_assert(ev->_major == CORBA_NO_EXCEPTION);
  75.  
  76.     poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, "RootPOA", ev);
  77.     g_assert(ev->_major == CORBA_NO_EXCEPTION);
  78.  
  79.     objid = PortableServer_POA_activate_object(poa, (PortableServer_ServantBase *)&servant, ev);
  80.     g_assert(ev->_major == CORBA_NO_EXCEPTION);
  81.  
  82.     servant.this = PortableServer_POA_servant_to_reference(poa, (PortableServer_ServantBase *)&servant, ev);
  83.     g_assert(ev->_major == CORBA_NO_EXCEPTION);
  84.  
  85.     CORBA_free(objid);
  86.  
  87.     return CORBA_Object_duplicate(servant.this, ev);
  88. }
  89.  
  90. static PyObject *
  91. _wrap_create_TestCall(PyObject *self, PyObject *args)
  92. {
  93.     PyCORBA_ORB *orb;
  94.     CORBA_Environment ev;
  95.     CORBA_Object objref;
  96.     PyObject *py_objref;
  97.  
  98.     if (!PyArg_ParseTuple(args, "O!", &PyCORBA_ORB_Type, &orb))
  99.     return NULL;
  100.  
  101.     CORBA_exception_init(&ev);
  102.     objref = create_TestCall(orb->orb, &ev);
  103.     g_assert(ev._major == CORBA_NO_EXCEPTION);
  104.  
  105.     py_objref = pycorba_object_new(objref);
  106.     CORBA_Object_release(objref, NULL);
  107.     return py_objref;
  108. }
  109.  
  110. static PyMethodDef cTestCall_functions[] = {
  111.     { "create_TestCall", (PyCFunction)_wrap_create_TestCall, METH_VARARGS },
  112.     { NULL, NULL, 0 }
  113. };
  114.  
  115. void initcTestCall(void);
  116.  
  117. DL_EXPORT(void)
  118. initcTestCall(void)
  119. {
  120.     PyObject *mod;
  121.  
  122.     init_pyorbit();
  123.  
  124.     //ORBit_small_flags &= ~ ORBIT_SMALL_FAST_LOCALS;
  125.  
  126.     mod = Py_InitModule("cTestCall", cTestCall_functions);
  127. }
  128.